package ailibaba.number1;

import java.util.Scanner;

/**
 * @Author Jun jie Yi
 * @Date 2022/3/16 19:52
 */
public class MyMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //组数
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            int[][] xy = new int[2][n];
            //输入 x
            for (int j = 0; j < n; j++) {
                xy[0][j] = scanner.nextInt();
            }
            //输入 y
            for (int j = 0; j < n; j++) {
                xy[1][j] = scanner.nextInt();
            }
            //ll.add(xy);
            System.out.println(getSum(xy[0], xy[1]));
        }
    }

    public static int getSum(int[] x, int[] y) {
        //1.先进行排序
        ShellSort(x, y);
        //2.找到 y 的最长比较序列
        return getMax(y);
    }

    public static int getMax(int[] a) {
        //用于标记，优化运算速度
        int[] flag = new int[a.length];
        int max = 0;
        for (int i = 0; i < a.length; i++) {
            //if (a.length - i < max) break;
            if (flag[i] == 1) continue;
            int f = a[i], sum = 1;
            flag[i] = 1;
            for (int j = i + 1; j < a.length; j++) {
                if (a[j] > f) {
                    sum++;
                    f = a[j];
                    flag[j] = 1;
                }
            }
            if (max < sum) max = sum;
        }
        return max;
    }

    public static void ShellSort(int[] x, int[] y) {
        int n = x.length;
        int d = n / 2; //设置起始增量
        while (d >= 1) //增量为1时排序结束
        {
            for (int k = 0; k < d; ++k) //遍历所有的子序
            {
                for (int i = k + d; i < n; i += d) //对每个子序进行插入排序
                {
                    int tx = x[i];
                    int ty = y[i];//y跟着变数字
                    int j = i - d;
                    while (j >= k && x[j] > tx) {
                        x[j + d] = x[j];
                        y[j + d] = y[j];//y跟着变数字
                        j -= d;
                    }
                    x[j + d] = tx;
                    y[j + d] = ty;//y跟着变数字
                }
            }
            d = d / 2; //缩小增量
        }
    }
}
